import { PageTool } from "../../../common/global/PageTool";
import { WardrobeType } from "../wardrobe/WardrobeType";
import { Cache } from "../../cache/Cache";
import { TilePanel } from "../equipment/TilePanel";
import { FashionBoxItemRender } from "./FashionBoxItemRender";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { WardrobeItemInfo } from "../wardrobe/WardrobeItemInfo";
type int = number;
//class FashionBoxItemList
    
    export  class FashionBoxItemList /* flash.display.Sprite */
    {
        constructor(arg1: int)
        {
            
            this._itemList = [];
            this._pageTool = new PageTool([], 12);
            this.init(arg1);
            return;
        }

        /* internal  */init(arg1: int): void
        {
            var loc1=[];
            if (arg1 != WardrobeType.WardrobeFashion) 
            {
                loc1 = Cache.instance.wardrobe.getAllWing();
            }
            else 
            {
                loc1 = Cache.instance.wardrobe.getAllFashion();
            }
            this._tilePanel = new TilePanel();
            this._tilePanel.horizontalGap = 5;
            this._tilePanel.verticalGap = 5;
            this._tilePanel.columnWidth = 88;
            this._tilePanel.rowHeight = 106;
            this._tilePanel.columnCount = 4;
            this._tilePanel.rowCount = 3;
            this._tilePanel.setSize(380, 344);
            this._tilePanel.setStyle("cellRenderer", FashionBoxItemRender);
            this._tilePanel.move(0, 0);
            addChild(this._tilePanel);
            this._pageTool.array = loc1;
            ObjCreate.createBg(8, 370, 362, 2, this, ImagesConst.SplitLine);
            this._pagebar = new PageSelecter();
            this._pagebar.mode = PageSelecter.CompleteMode;
            this._pagebar.move(120, 377);
            this._pagebar.maxPage = Math.ceil(loc1.length / this.ITEMNUM);
            this._pagebar.currentPage = 1;
            this._pagebar.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            addChild(this._pagebar);
            this.onCurPageChangeHandler();
            return;
        }

        /* internal  */onCurPageChangeHandler(arg1: Object /* flash.events.Event */=null): void
        {
            var loc1=this._pagebar.currentPage;
            var loc2=this._pageTool.getByPageNo(loc1);
            this._tilePanel.dataProvider = new DataProvider(loc2);
            dispatchEvent(new Object /* flash.events.Event */(flash.events.Event.CHANGE));
            return;
        }

        public updateItemData(arg1: Array<any>): void
        {
            this._pagebar.currentPage = 1;
            this._pageTool.array = arg1;
            this._pagebar.maxPage = Math.ceil(arg1.length / this.ITEMNUM);
            this.onCurPageChangeHandler();
            return;
        }

        public updateSelected(arg1: int): void
        {
            this._tilePanel.selectedIndex = arg1;
            return;
        }

        public getFirstInfo(): WardrobeItemInfo
        {
            var loc1=null;
            var loc2=this._pagebar.currentPage;
            var loc3=this._pageTool.getByPageNo(loc2);
            if (loc3 && loc3.length > 0) 
            {
                loc1 = loc3[0].wardrobeItemInfo;
            }
            return loc1;
        }

        /* internal */ /* const */ITEMNUM: int=12;

        /* internal */ /* var */_itemList: Array<any>;

        /* internal */ /* var */_pagebar: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_tilePanel: TilePanel;

        /* internal */ /* var */_firstX: int=0;

        /* internal */ /* var */_firstY: int=0;
    }
